﻿
@{
    ViewBag.Title = "Show3D";
}
<div class="layui-form-item">
    <div class="layui-inline">
        <a class="layui-btn" id="btnFire">火情</a>
        <a class="layui-btn" id="btnFireCancel">取消</a>
        <a class="layui-btn" id="btnReplay">轨迹回放</a>
        <a class="layui-btn" id="btnReplayCancel">取消</a>
        <a class="layui-btn" id="btnEmpty">未分配区域</a>
    </div>
</div>
<div style="top: 58px;bottom: 0;width: 100%;position: absolute;">
    <div class="layui-show" style="width: 100% !important;height: 100% !important;">
        <iframe id='childFrame' style="width:100%;height:100%;" frameborder="0" src="http://www.thingjs.com/guide/sampleindex.html?m=64614/Demo.js"></iframe>
    </div>
</div>
<script>
    layui.use(['jquery'], function () {
        var $ = layui.jquery;
        $("#btnFire").click(function () {
            callChild({ 'action': 'fire', 'names': ['cangku01_kuwei01', 'cangku01_kuwei02'] });
        })
        $("#btnFireCancel").click(function () {
            callChild({ 'action': 'fireCancel', 'names': ['cangku01_kuwei01'] });
        })
        $("#btnReplay").click(function () {
            callChild({ 'action': 'replay', 'name': 'movecar', 'points': [[5, 0, 5], [5, 0, 55], [120, 0, 55], [120, 0, 5], [5, 0, 5]], 'info': { "车牌": "豫A12345", "公司": "中储恒科", "状态": "行驶" }});
        })
        $("#btnReplayCancel").click(function () {
            callChild({ 'action': 'replayCancel', 'name': 'movecar' });
        })
        $("#btnEmpty").click(function () {
            callChild({ 'action': 'empty', 'name': 'cangku01_kuwei04' });
        })
    });
    function callChild(data) {
        callChildFunc('receiveMainFunc', data);
    }
    //调用子页面函数
    function callChildFunc(funcName, data) {
        var iframe = window.frames['childFrame'];
        var message = {
            'funcName': funcName,
            'param': data
        }
        iframe.contentWindow.postMessage(message, '*');
    }
    //监听子页面调用本页面函数
    window.addEventListener('message', function (e) {
        var data = e.data;
        if (data.hasOwnProperty("funcName")) {
            var funcName = data.funcName;
            var param = data.param;
            window[funcName](param);
        }
    });
    function getUserAuth() {
        var userAuth = [];
        if ("@GlobalSupport.CurrentUser.UserName" == "admin") {
            userAuth = [{ "name": "cangku01_kuwei01", "info": { "归属": "A公司", "面积": "50平方", "货物数量": "100" } }, { "name": "cangku01_kuwei02", "info": { "归属": "B公司", "面积": "100平方" } }];
        }
        else {
            userAuth = [{ "name": "cangku01_kuwei03", "info": { "归属": "C公司", "面积": "50平方" } }];
        }
        callChildFunc("receiveUserAuth", userAuth);
    }
</script>

